#include <iostream>
#include <thread>
#include <chrono>
#include <opencv2/opencv.hpp>

int main(int, char **)
{
    int counter = 0;
    // cv::VideoCapture *stream = new cv::VideoCapture("rtsp://113.98.245.183:2554/openUrl/boik6nm");
    cv::VideoCapture cam("rtsp://113.98.245.183:2554/openUrl/YfHamzK");
    // cam.open("./test.mp4");
    // if (!stream->isOpened()) return -1;
    if (!cam.isOpened())
    {
        std::cerr << "ERROR! Unable to open camera" << std::endl;
        return -1;
    }
    cv::Mat frame;
    while (true)
    {
        cam.read(frame);
        // cv::imwrite("test.jpg", frame);

        if (frame.empty())
        {
            std::cout << "ERROR! blank frame grabbed" << std::endl;
            std::this_thread::sleep_for(std::chrono::seconds(1));
            continue;
        }
        std::cout << "I'm writing: " << counter << std::endl;
        counter++;
        // std::this_thread::sleep_for(std::chrono::seconds(3));
    }
    return 0;
}
